package top.mccat.common.core.controller.bk;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.mccat.common.annotation.Log;
import top.mccat.common.core.controller.BaseController;
import top.mccat.common.core.domain.AjaxResult;
import top.mccat.common.core.domain.bk.BkSupplieRecord;
import top.mccat.common.enums.BusinessType;
import top.mccat.common.core.page.TableDataInfo;
import top.mccat.common.exception.bk.BaseItemNotFoundException;
import top.mccat.common.service.IBkSupplieRecordService;
import top.mccat.common.utils.poi.ExcelUtil;

/**
 * 【采购记录】Controller
 * 
 * @author ruoyi
 * @date 2022-11-06
 */
@RestController
@RequestMapping("/bk/record")
public class BkSupplieRecordController extends BaseController
{
    @Autowired
    private IBkSupplieRecordService bkSupplieRecordService;

    /**
     * 查询【采购记录】列表
     */
    @PreAuthorize("@ss.hasPermi('bk:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(BkSupplieRecord bkSupplieRecord)
    {
        startPage();
        List<BkSupplieRecord> list = bkSupplieRecordService.selectBkSupplieRecordList(bkSupplieRecord);
        return getDataTable(list);
    }

    /**
     * 导出【采购记录】列表
     */
    @PreAuthorize("@ss.hasPermi('bk:record:export')")
    @Log(title = "【采购记录】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BkSupplieRecord bkSupplieRecord)
    {
        List<BkSupplieRecord> list = bkSupplieRecordService.selectBkSupplieRecordList(bkSupplieRecord);
        ExcelUtil<BkSupplieRecord> util = new ExcelUtil<BkSupplieRecord>(BkSupplieRecord.class);
        util.exportExcel(response, list, "【采购记录】数据");
    }

    /**
     * 获取【采购记录】详细信息
     */
    @PreAuthorize("@ss.hasPermi('bk:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(bkSupplieRecordService.selectBkSupplieRecordById(id));
    }

    /**
     * 新增【采购记录】
     */
    @PreAuthorize("@ss.hasPermi('bk:record:add')")
    @Log(title = "【采购记录】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BkSupplieRecord bkSupplieRecord)
    {
        AjaxResult ajaxResult;
        try {
            ajaxResult = toAjax(bkSupplieRecordService.insertBkSupplieRecord(bkSupplieRecord));
        } catch (Exception e) {
            e.printStackTrace();
            ajaxResult = AjaxResult.error(e.getMessage());
        }
        return ajaxResult;
    }

    /**
     * 修改【采购记录】
     */
    @PreAuthorize("@ss.hasPermi('bk:record:edit')")
    @Log(title = "【采购记录】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BkSupplieRecord bkSupplieRecord)
    {
        return toAjax(bkSupplieRecordService.updateBkSupplieRecord(bkSupplieRecord));
    }

    /**
     * 删除【采购记录】
     */
    @PreAuthorize("@ss.hasPermi('bk:record:remove')")
    @Log(title = "【采购记录】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(bkSupplieRecordService.deleteBkSupplieRecordByIds(ids));
    }
}
